package com.fulu.javabase.juc.lock;

import java.util.concurrent.locks.LockSupport;

public class LockSupportTest {

    public static void main(String[] args) throws InterruptedException {
        LockSupportTest lst = new LockSupportTest();
        Thread t1 = new Thread(lst::test);
        Thread t2 = new Thread(lst::test);
        t1.start();
        Thread.sleep(1000);
        t2.start();
        Thread.sleep(2000);
        t1.interrupt();
        LockSupport.unpark(t2);
    }

    public synchronized void test(){

        Thread cu = Thread.currentThread();
        String tn = cu.getName();
        System.out.println("进入线程" + tn);
        LockSupport.park();
        if(cu.isInterrupted()){
            System.out.println("线程退出" + tn);
        }
        System.out.println("线程继续" + tn);
    }
}
